package com.zixuan.gulicollege.service_order.controller;


import com.alipay.api.AlipayApiException;
import com.zixuan.gulicollege.common_utils.R;
import com.zixuan.gulicollege.entity.order.Order;
import com.zixuan.gulicollege.service_order.service.PayLogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

/**
 * <p>
 * 支付日志表 前端控制器
 * </p>
 *
 * @author zixuan
 * @since 2021-05-26
 */
@RestController
@RequestMapping("/service_order/pay")
public class PayLogController {

    @Autowired
    private PayLogService payLogService;

    /**
     * 支付宝支付接口
     * @param order
     * @return
     * @throws AlipayApiException
     */
    @PostMapping("/aliPay")
    public R aliPay(@RequestBody Order order) throws AlipayApiException {
        String result = payLogService.aliPay(order);
        return R.ok().data("result", result);
    }

    /**
     * 支付宝验签接口
     * @param request
     * @return
     * @throws AlipayApiException
     */
    @PostMapping("/callBack")
    public String callBack(HttpServletRequest request) throws AlipayApiException {
        return payLogService.callBack(request);
    }

}

